package com.mall.dubbo.api;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.dubbo.mapper.PmsBrandMapper;
import com.mall.model.domain.PmsBrand;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.List;

/**
 * @author xyiaao
 * @description 针对表【pms_brand(品牌表)】的数据库操作Api实现
 * @createDate 2022-03-29 19:46:09
 */
@DubboService
public class PmsBrandApiImpl extends ServiceImpl<PmsBrandMapper, PmsBrand>
        implements PmsBrandApi {

    @Autowired
    private PmsBrandMapper pmsBrandMapper;

    @Override
    public PmsBrand findBrand(String name) {
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PmsBrand::getName, name);
        PmsBrand pmsBrand = pmsBrandMapper.selectOne(wrapper);
        return pmsBrand;
    }

    @Override
    public void saveBrand(PmsBrand pmsBrand) {
        pmsBrandMapper.insert(pmsBrand);

    }

    @Override
    public void deleteBrandIds(Long[] ids) {
        pmsBrandMapper.deleteBatchIds(Arrays.asList(ids));
    }

    @Override
    public void deleteBrandId(Long id) {
        pmsBrandMapper.deleteById(id);
    }

    @Override
    public Page<PmsBrand> queryList(String keyword, Integer pageNum, Integer pageSize) {

        Page<PmsBrand> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<PmsBrand> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(keyword != null, PmsBrand::getName, keyword);
        Page<PmsBrand> iPage = pmsBrandMapper.selectPage(page, wrapper);
        return iPage;
    }

    @Override
    public List<PmsBrand> listAll() {

        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.isNotNull(PmsBrand::getName);
        List<PmsBrand> pmsBrands = pmsBrandMapper.selectList(queryWrapper);
        return pmsBrands;
    }

    @Override
    public List<PmsBrand> findBrandByids(Long[] ids) {

        LambdaQueryWrapper<PmsBrand> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(PmsBrand::getId, ids);
        List<PmsBrand> pmsBrands = pmsBrandMapper.selectList(queryWrapper);
        return pmsBrands;
    }

    @Override
    public void updateBrand(PmsBrand brand) {

        pmsBrandMapper.updateById(brand);
    }

    @Override
    public PmsBrand findBrandByid(Long id) {

        return pmsBrandMapper.selectById(Convert.toLong(id));
    }
}




